from numpy import array
class AnalyticThing:
	def __init__(self,data,top):
		self.stable_list = []
		self.data = data
		self.top = top
		for e in self.data:
			s = self.data[e]["stability"]
			self.stable_list.append((s,e))
		self.stable_list.sort(reverse=True)
		self.top_concepts = array([(e[1],e[0]) for e in self.stable_list[:self.top]])
	def get_stability_mean(self):
		'''Getting stability mean'''
		print "\tGetting stability mean"
		return array([s[0] for s in self.stable_list]).mean()

	def get_top_concepts_stability(self):
		return array([e[0] for e in self.stable_list[:self.top]]).mean()
	def get_amount_of_concepts(self):
		return len(self.data.keys())
	
	def compare_with_other_data(self,comparer):
		'''Comparing with real data'''
		print "\tComparing with real data"
		count = 0
		for e in self.data.keys():
			if comparer.get(str(self.data[e]["attributes"]), False) != False:
				count += 1
		return count
	def compare_with_other_data_and_log(self,comparer,logname):
		'''Comparing with real data'''
		print "\tComparing with real data and logging"
		f = open("y"+logname,"w")
		fn = open("n"+logname,"w")
		count = 0
		for e in self.data.keys():
			if comparer.get(str(self.data[e]["attributes"]), False) != False:
				f.write(str(self.data[e]["stability"])+"\n")
				count += 1
			else:
				fn.write(str(self.data[e]["stability"])+"\n")
		f.close()
		fn.close()
		return count
